package com.work.mdass.service;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.work.mdass.domain.OrderApplyDetials;
import com.work.mdass.properties.OrderApplyDetialsInterface;

@Service
public class OrderApplyDetialsService {

	@Autowired
	private OrderApplyDetialsInterface orderApplyDetialsInterface;
	
	/*
	 * 添加一条明细
	 */
	public OrderApplyDetials addOrderApplyDetials(OrderApplyDetials orderApplyDetials){
		
		return orderApplyDetialsInterface.save(orderApplyDetials);
	}
	/*
	 * 通过申请编号查找明细
	 */
	public OrderApplyDetials getDetials(Integer applySerial){
		
	 return  orderApplyDetialsInterface.findByApplySerial(applySerial);
		
	}
	/*
	 * 通过编号获取明细
	 */
	public OrderApplyDetials getById(Integer id) {
		return orderApplyDetialsInterface.findOne(id);
	}
	/*
	 * 通过课程名称查找、
	 */
	public OrderApplyDetials getByCourseName(String courseName) {
		return orderApplyDetialsInterface.findByCourseName(courseName);
	}
	/*
	 * 删除一条明细
	 */
	public OrderApplyDetials deleteDetials(Integer id) {
		
		orderApplyDetialsInterface.delete(id);
		
		return null;
	}
	/*
	 * 修改一条明细
	 */
	public OrderApplyDetials updata(OrderApplyDetials orderApplyDetials) {
		return orderApplyDetialsInterface.save(orderApplyDetials);
	}
	/*
	 * 通过教师名称查找
	 */
	public Map<Object,Object> getByTName(String tName){
		
		List<OrderApplyDetials> detials = orderApplyDetialsInterface.findByTName(tName);
		
		Map<Object,Object> result = new HashMap<>();
		
		if(detials.size()!=0) {
			result.put("code", 0);
			result.put("msg", "成功");
			result.put("data", detials);
			result.put("count", detials.size());
		}else{
			result.put("code", 1);
			result.put("msg", "暂时没有征订任何教材");
			result.put("data", detials);
			result.put("count", detials.size());
		}	
		return result;
		
	}
	/*
	 * 通过关键字匹配
	 */
	public Map<Object,Object> getByKeyWord(String keyWord){
		List<OrderApplyDetials> detials = orderApplyDetialsInterface.findByNameLike(keyWord);
		
		Map<Object,Object> result = new HashMap<>();
		
		if(detials.size()!=0) {
			result.put("code", 0);
			result.put("msg", "成功");
			result.put("data", detials);
			result.put("count", detials.size());
		}else{
			result.put("code", 1);
			result.put("msg", "暂时没有征订任何教材");
			result.put("data", detials);
			result.put("count", detials.size());
		}
		return result;
	}
	/*
	 * 通过关键字匹配教材名称模糊搜索,教师名称
	 * @return {name,tName}
	 */
	public Map<Object,Object> userAnalysis(String tName,String keyWord){
		
		List<OrderApplyDetials> detials = orderApplyDetialsInterface.findByTNameAndNameLike(tName, keyWord);
		
		Map<Object,Object> result = new HashMap<>();
		
		if(detials.size()!=0) {
			result.put("code", 0);
			result.put("msg", "成功");
			result.put("data", detials);
			result.put("count", detials.size());
		}else{
			result.put("code", 1);
			result.put("msg", "暂时没有征订任何教材");
			result.put("data", detials);
			result.put("count", detials.size());
		}
		return result;
	}
}
